<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "branch".
 *
 * @property integer $id_branch
 * @property integer $id_company
 * @property string $name
 * @property string $address
 * @property string $email
 * @property string $phone
 * @property integer $is_main
 * @property string $updated
 * @property string $created
 *
 * @property Company $idCompany
 * @property ProductBranch[] $productBranches
 */
class Branch extends \yii\db\ActiveRecord
{
    const IS_MAIN = 1;
    const IS_NOT_MAIN = 1;
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'branch';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id_company'], 'integer'],
            [['updated', 'created'], 'safe'],
            [['name', 'address', 'email', 'phone'], 'string', 'max' => 255]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id_branch' => 'Id Branch',
            'id_company' => 'Id Company',
            'name' => 'Name',
            'address' => 'Address',
            'email' => 'Email',
            'phone' => 'Phone',
            'updated' => 'Updated',
            'created' => 'Created',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getIdCompany()
    {
        return $this->hasOne(Company::className(), ['id_company' => 'id_company']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getProductBranches()
    {
        return $this->hasMany(ProductBranch::className(), ['id_branch' => 'id_branch']);
    }
}
